import 'package:json_annotation/json_annotation.dart';

part 'get_info_res.g.dart';

@JsonSerializable(fieldRename: FieldRename.none)
class GetInfoRes {
  final int? code;
  final UserInfo? data;
  final String? msg;

  const GetInfoRes({
    this.code,
    this.data,
    this.msg,
  });

  factory GetInfoRes.fromJson(Map<String, dynamic> json) =>
      _$GetInfoResFromJson(json);

  Map<String, dynamic> toJson() => _$GetInfoResToJson(this);

  GetInfoRes copyWith({
    int? code,
    UserInfo? data,
    String? msg,
  }) {
    return GetInfoRes(
      code: code ?? this.code,
      data: data ?? this.data,
      msg: msg ?? this.msg,
    );
  }
}

@JsonSerializable(fieldRename: FieldRename.none)
class UserInfo {
  final int? id;
  final String? username;
  final String? nickname;
  final String? email;
  final String? mobile;
  final int? sex;
  final String? avatar;
  final String? loginIp;
  final int? loginDate;
  final int? createTime;
  final List<Roles>? roles;
  final Dept? dept;
  final List<Posts>? posts;

  const UserInfo({
    this.id,
    this.username,
    this.nickname,
    this.email,
    this.mobile,
    this.sex,
    this.avatar,
    this.loginIp,
    this.loginDate,
    this.createTime,
    this.roles,
    this.dept,
    this.posts,
  });

  factory UserInfo.fromJson(Map<String, dynamic> json) =>
      _$UserInfoFromJson(json);

  Map<String, dynamic> toJson() => _$UserInfoToJson(this);

  UserInfo copyWith({
    int? id,
    String? username,
    String? nickname,
    String? email,
    String? mobile,
    int? sex,
    String? avatar,
    String? loginIp,
    int? loginDate,
    int? createTime,
    List<Roles>? roles,
    Dept? dept,
    List<Posts>? posts,
  }) {
    return UserInfo(
      id: id ?? this.id,
      username: username ?? this.username,
      nickname: nickname ?? this.nickname,
      email: email ?? this.email,
      mobile: mobile ?? this.mobile,
      sex: sex ?? this.sex,
      avatar: avatar ?? this.avatar,
      loginIp: loginIp ?? this.loginIp,
      loginDate: loginDate ?? this.loginDate,
      createTime: createTime ?? this.createTime,
      roles: roles ?? this.roles,
      dept: dept ?? this.dept,
      posts: posts ?? this.posts,
    );
  }
}

@JsonSerializable(fieldRename: FieldRename.none)
class Roles {
  final int? id;
  final String? name;

  const Roles({
    this.id,
    this.name,
  });

  factory Roles.fromJson(Map<String, dynamic> json) =>
      _$RolesFromJson(json);

  Map<String, dynamic> toJson() => _$RolesToJson(this);

  Roles copyWith({
    int? id,
    String? name,
  }) {
    return Roles(
      id: id ?? this.id,
      name: name ?? this.name,
    );
  }
}

@JsonSerializable(fieldRename: FieldRename.none)
class Dept {
  final int? id;
  final String? name;
  final int? parentId;

  const Dept({
    this.id,
    this.name,
    this.parentId,
  });

  factory Dept.fromJson(Map<String, dynamic> json) =>
      _$DeptFromJson(json);

  Map<String, dynamic> toJson() => _$DeptToJson(this);

  Dept copyWith({
    int? id,
    String? name,
    int? parentId,
  }) {
    return Dept(
      id: id ?? this.id,
      name: name ?? this.name,
      parentId: parentId ?? this.parentId,
    );
  }
}

@JsonSerializable(fieldRename: FieldRename.none)
class Posts {
  final int? id;
  final String? name;

  const Posts({
    this.id,
    this.name,
  });

  factory Posts.fromJson(Map<String, dynamic> json) =>
      _$PostsFromJson(json);

  Map<String, dynamic> toJson() => _$PostsToJson(this);

  Posts copyWith({
    int? id,
    String? name,
  }) {
    return Posts(
      id: id ?? this.id,
      name: name ?? this.name,
    );
  }
}
